package com.qpx.jxcmessage.dlx;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DTXRabbitMQConfig {


    /**
     * 订单队列
     * @return
     */
    @Bean
    public Queue queueOrder(){
        Map<String,Object> m = new HashMap<String,Object>();
        m.put("x-message-ttl",20000);
        m.put("x-dead-letter-exchange","dlx.exchange");
        return new Queue("order_queue",true,false,false,m);
    }

    /**
     * 订单交换机
     * @return
     */
    @Bean
    public TopicExchange topicExchangeOrder(){
        return new TopicExchange("order_exchange");
    }

    @Bean
    public Binding bindingOrder(){
        return BindingBuilder.bind(queueOrder()).to(topicExchangeOrder()).with("order.#");
    }

    /**
     * 死信交换机
     * @return
     */
    @Bean
    public TopicExchange topicExchangeOrderDTX(){
        return new TopicExchange("dlx.exchange");
    }

    /**
     * 死信队列
     * @return
     */
    @Bean
    public Queue queueOrderDTX(){
        return new Queue("dlx.queue");
    }

    @Bean
    public Binding bindingDTX(){
        return BindingBuilder.bind(queueOrderDTX()).to(topicExchangeOrderDTX()).with("order.#");
    }




}
